// 云函数入口文件
const cloud = require('wx-server-sdk')
cloud.init()
const db = cloud.database();

// 云函数入口函数
//添加评论
exports.main = async (event, context) => {
  const openid = cloud.getWXContext().OPENID
  var commentData = event;
  var {content} = event;
  var code= await cloud.callFunction({
    name:"xiangcun_checkSafe",
    data:{
      content,
    },
  })
  if(code.result.errCode==0){
    commentData.openid = openid
    var posttime = new Date().getTime()
     commentData.posttime = posttime
    return await db.collection("sptrival_comment").add({
    data:commentData
  })
  }
  else
  {
    return code.result
  }
  

}